package gdr.battle.graphics;

import gdr.battle.data.map.*;

import java.awt.*;

public class GraphicalMapUnitGate extends GraphicalMapUnit{
	protected Color coloreInterno;
	protected int bordoInterno = 3;
	
	public void render(Graphics2D g){
		boolean selected = coordinateCalc.getCenter().equals(mapUnit.getPos());
		if (mapUnit instanceof BattleMapUnitEmpty && !selected) return;
		
		Color c = color;
		bordo = color.darker().darker();
		
		if (mapUnit.isEvidenziato())
			c = Color.pink;
		if (selected)
			c = Color.red;

		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g.setStroke(new BasicStroke(2));

		int baseX = coordinateCalc.getX(mapUnit.getPos());
		int baseY = coordinateCalc.getY(mapUnit.getPos());
		int width = CoordinateCalculator.UNIT_WIDTH;
		int height = CoordinateCalculator.UNIT_HEIGHT;
		
		bordoInterno = 7;
		g.setColor(coloreInterno);
		g.fillRect(baseX, baseY, width, height);
		g.setColor(coloreInterno.darker());
		g.drawRect(baseX, baseY, width, height);
		
		g.setColor(c);
		g.fillRect(baseX+bordoInterno, baseY+bordoInterno, width-2*bordoInterno, height-2*bordoInterno);
		//g.setColor(bordo);
		//g.drawRect(baseX+bordoInterno, baseY+bordoInterno, width-2*bordoInterno, height-2*bordoInterno);
		
		Position base = new Position(mapUnit.getPos());
		base.setZ(0);
		int x = baseX;
		int y = baseY+height;
		height = coordinateCalc.getY(base)-baseY;
		g.setColor(Color.green);
		g.fillRect(x, y, width, mapUnit.getPos().getZ()*CoordinateCalculator.UNIT_SIZE);
		g.setColor(bordo);
		g.drawRect(x, y, width, mapUnit.getPos().getZ()*CoordinateCalculator.UNIT_SIZE);
		
		
		/*//disegna base
		Polygon pol = getBase();
		g.setColor(c);
		g.fillPolygon(pol);
		g.setColor(bordo);
		g.drawPolygon(pol);
		//disegna gate
		pol = getBaseGate();
		g.setColor(coloreInterno);
		g.fillPolygon(pol);
		g.setColor(coloreInterno.darker());
		g.drawPolygon(pol);
		//disegna bordo
		pol = getBordo();
		g.setColor(color);
		g.fillPolygon(pol);
		g.setColor(bordo);
		g.drawPolygon(pol);*/
	}

	protected Polygon getBaseGate(){
		Polygon pol = new Polygon();
		int baseX = coordinateCalc.getX(mapUnit.getPos());
		int baseY = coordinateCalc.getY(mapUnit.getPos());
		int width = (int)Math.round(CoordinateCalculator.COS*CoordinateCalculator.UNIT_WIDTH);
		int height = (int)Math.round(CoordinateCalculator.SIN*CoordinateCalculator.UNIT_HEIGHT);
		
		int x1 = baseX + width/2 - bordoInterno;
		int y1 = baseY + height/2 + bordoInterno;
		
		int x2 = baseX + width/2 - bordoInterno;
		int y2 = baseY + 3*height/2 - bordoInterno;
		
		int x3 = baseX - width/2 + bordoInterno;
		int y3 = baseY + 3*height/2 - bordoInterno;
		
		int x4 = baseX - width/2 + bordoInterno;
		int y4 = baseY + height/2 + bordoInterno;
		
		pol.addPoint(x1, y1);
		pol.addPoint(x2, y2);
		pol.addPoint(x3, y3);
		pol.addPoint(x4, y4);
		
		return pol;
	}
	public Color getColoreInterno() {
		return coloreInterno;
	}

	public void setColoreInterno(Color coloreInterno) {
		this.coloreInterno = coloreInterno;
	}
}
